/*    */ package cn.zzuisa.news.servlet;
/*    */ 
/*    */ import cn.zzuisa.news.entity.IprNewsInfo;
/*    */ import cn.zzuisa.news.entity.IprNewsType;
/*    */ import cn.zzuisa.news.enums.CommonEnums;
/*    */ import cn.zzuisa.news.form.IprNewsInfoForm;
/*    */ import cn.zzuisa.news.service.IprNewsService;
/*    */ import cn.zzuisa.news.service.impl.IprNewsServiceImpl;
/*    */ import cn.zzuisa.news.util.JsonUtil;
/*    */ import cn.zzuisa.news.util.ResultVOUtil;
/*    */ import com.google.gson.Gson;
/*    */ import java.io.IOException;
/*    */ import java.util.List;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.annotation.WebServlet;
/*    */ import javax.servlet.http.HttpServlet;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ 
/*    */ @WebServlet(name = "indexnews", urlPatterns = {"/indexnews"}, asyncSupported = true)
/*    */ public class indexNewsServlet
/*    */   extends HttpServlet
/*    */ {
/* 25 */   private IprNewsService iprNewsServiceImpl = new IprNewsServiceImpl();
/*    */ 
/*    */   
/*    */   protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/* 29 */     String method = req.getParameter("method");
/* 30 */     if (method == null) {
/* 31 */       List<IprNewsInfo> listinfo = this.iprNewsServiceImpl.listinfoByType(null);
/* 32 */       req.setAttribute("list", listinfo);
/* 33 */       req.getRequestDispatcher("WEB-INF/ftl/index/indexNews.ftl").forward(req, resp);
/*    */     }
/* 35 */     else if (method.equals("type")) {
/* 36 */       String key = req.getParameter("key");
/* 37 */       String doer = req.getParameter("doer");
/* 38 */       String id = req.getParameter("id");
/* 39 */       List<IprNewsType> listtype = this.iprNewsServiceImpl.listtype();
/* 40 */       req.setAttribute("types", listtype);
/* 41 */       if (key != null) {
/* 42 */         IprNewsType iprNewsType = this.iprNewsServiceImpl.findIprNewsTypeById(Integer.valueOf(Integer.parseInt(key)));
/* 43 */         req.setAttribute("type", iprNewsType);
/* 44 */         if (doer != null) {
/* 45 */           List<IprNewsInfo> list = this.iprNewsServiceImpl.listinfoByType(Integer.valueOf(Integer.parseInt(key)));
/* 46 */           req.setAttribute("list", list);
/* 47 */           if (id != null) {
/* 48 */             IprNewsInfo iprNewsInfo = this.iprNewsServiceImpl.findInfoById(Integer.valueOf(Integer.parseInt(id)));
/* 49 */             req.setAttribute("info", iprNewsInfo);
/*    */           } 
/*    */         } 
/*    */       } 
/*    */       
/* 54 */       req.getRequestDispatcher("WEB-INF/ftl/Ipr/addIprNews.ftl").forward(req, resp);
/* 55 */     } else if (method.equals("add")) {
/* 56 */       String json = JsonUtil.getStrResponse(req);
/* 57 */       IprNewsInfoForm iprNewsInfoForm = (IprNewsInfoForm)(new Gson()).fromJson(json, IprNewsInfoForm.class);
/* 58 */       if (this.iprNewsServiceImpl.addNewsInfo(iprNewsInfoForm))
/* 59 */       { resp.getWriter().println(JsonUtil.setData(ResultVOUtil.success())); }
/*    */       else
/* 61 */       { resp.getWriter().println(JsonUtil.setData(ResultVOUtil.failed(CommonEnums.PARAM_ERROR))); } 
/* 62 */     } else if (method.equals("edit")) {
/* 63 */       String json = JsonUtil.getStrResponse(req);
/* 64 */       Integer id = Integer.valueOf(Integer.parseInt(req.getParameter("id")));
/* 65 */       IprNewsInfoForm iprNewsInfoForm = (IprNewsInfoForm)(new Gson()).fromJson(json, IprNewsInfoForm.class);
/* 66 */       if (this.iprNewsServiceImpl.editByFormAndId(iprNewsInfoForm, id))
/* 67 */       { resp.getWriter().println(JsonUtil.setData(ResultVOUtil.success())); }
/*    */       else
/* 69 */       { resp.getWriter().println(JsonUtil.setData(ResultVOUtil.failed(CommonEnums.PARAM_ERROR))); } 
/* 70 */     } else if (method.equals("delete")) {
/* 71 */       Integer id = Integer.valueOf(Integer.parseInt(req.getParameter("id")));
/* 72 */       if (this.iprNewsServiceImpl.delete(id)) {
/* 73 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.success()));
/*    */       } else {
/* 75 */         resp.getWriter().println(JsonUtil.setData(ResultVOUtil.failed(CommonEnums.PARAM_ERROR)));
/*    */       } 
/*    */     } 
/*    */   }
/*    */ }


/* Location:              /Users/frank/Desktop/admin/WEB-INF/classes/!/cn/zzuisa/news/servlet/indexNewsServlet.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.0.7
 */